<?php
class Info
{
	public $Table="info";
	public $InfoID;
	public $InfoName;
	public $InfoNameEng;
	
	function loadByKey($id)
	{
		$ob=new ClassConnect();
		$sql="select * from `".$this->Table."` where InfoID='".$id."'";
		$row=$ob->singleData($sql);
		$this->InfoID=$row['InfoID'];
		$this->InfoName=$row['InfoName'];
		$this->InfoNameEng=$row['InfoNameEng'];
	}
	function getTable($dk)
	{
		$ob=new ClassConnect();
		$sql="select * from `".$this->Table."` $dk";
		$data=$ob->mutiData($sql);
		return $data;
	}
	function travel($dk)
	{
		$arr=array();
		$data=$this->getTable($dk);
		for($i=0;$i<count($data);$i++)
			array_push($arr,$data[$i]['InfoID']);
		return $arr;
	}
	function insert($conn)
	{
		$ob=new ClassConnect();
		$field=array("InfoID","InfoName","InfoNameEng");
		$value=array($this->InfoID,$this->InfoName,$this->InfoNameEng);
		return $ob->insertData($conn,$this->Table,$field,$value);
	}
	function update($conn)
	{
		$ob=new ClassConnect();
		$field=array("InfoID","InfoName","InfoNameEng");
		$value=array($this->InfoID,$this->InfoName,$this->InfoNameEng);
		$where="InfoID = '".$this->InfoID."'";
		return $ob->updateData($conn,$this->Table,$field,$value,$where);			
	}
	function save($conn)
	{
		$obj=new Info();
		$obj->loadByKey($this->InfoID);
		if($obj->InfoID=="")
			$this->insert($conn);
		else
			$this->update($conn);
	}
	function incHitCounter($conn)
	{
		$obj=new Info();
		$obj->loadByKey("hitcounter");
		$hit=$obj->InfoID="hitcounter";
		$hit=$obj->InfoName;
		
		$obj->InfoName=$hit + 1;
		$obj->InfoNameEng=$hit + 1;
		$obj->save($conn);
	}
	function delete($conn)
	{
		$ob=new ClassConnect();		
		$where="InfoID = '".$this->InfoID."'";
		return $ob->deleteData($conn,$this->Table,$where);
			
	}
	function getNameArr($lang)
	{
		$ob=new ClassConnect();
		$sql="select * from `".$this->Table."`";
		$table=$ob->mutiData($sql);
		$row =array();
		for($i=0;$i<count($table);$i++)
		{
			$tem=array($table[$i]["InfoID"]=>$table[$i]["InfoName".$lang]);
			$row=array_merge($row,$tem);
		}
		return $row;
	}

}
?>
